<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <base href="${pageContext.request.contextPath}/">

    <link href="bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="bootstrap-table/bootstrap-table.min.css"/>
    <link rel="stylesheet" type="text/css" href="bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css"/>
</head>
<body>

<!--路径导航-->
<ol class="breadcrumb">
    <li>工作台</li>
    <li class="active">市场活动</li>
</ol>
<%--条件查询表单 a--%>
<div class="panel-body">
    <!--条件查询-->
    <div class="well well-sm">
        <form id="searchForm" class="form-inline" style="margin-bottom: 0">
            <div class="row" style="margin-bottom: 15px;">
                <div class="form-group col-md-4">
                    <label>&emsp;&emsp;名称</label>
                    <input type="text" id="name" class="form-control">
                </div>
                <div class="form-group col-md-4">
                    <label>开始日期</label>
                    <div class="input-group date myDatetime">
                        <input type="text" class="form-control" id="startDate" readonly/>
                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label>结束日期</label>
                    <div class="input-group date myDatetime">
                        <input type="text" class="form-control" id="endDate" readonly/>
                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group col-md-4">
                    <label>&emsp;所有者</label>
                    <select id="owner" class="form-control ownerSelect" style="width: 196px;">
                    </select>
                </div>
                <div class="form-group col-md-4">
                    <button type="button" class="btn btn-primary" onclick="$('#tab').bootstrapTable('refresh');">
                        <span class="glyphicon glyphicon-search"> 搜索</span>
                    </button>
                    <button type="button" class="btn btn-primary"
                            onclick="$('#searchForm')[0].reset();$('#tab').bootstrapTable('refresh');">
                        <span class="glyphicon glyphicon-refresh"> 清空</span>
                    </button>
                </div>
            </div>
        </form>
    </div>
    <!--工具栏和表格-->
    <div id="toolbar">
        <button type="button" class="btn btn-primary" onclick="$('#saveWin').modal('show');">
            <span class="glyphicon glyphicon-plus"> 新增</span>
        </button>
        <button type="button" class="btn btn-danger" onclick="removeBatch()">
            <span class="glyphicon glyphicon-trash"> 批量删除</span>
        </button>
    </div>
    <%--异步表格--%>
    <table id="tab" class="table table-hover table-striped table-bordered"></table>
</div>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--bootstrap-datetimepicker核心js-->
<script type="text/javascript" src="bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<!--bootstrap-datetimepicker中文语言包-->
<script type="text/javascript" src="bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<script type="text/javascript">

    $(function () {
        initTable();
        initRelation();
        //清空模态框中的表单
        $('#saveWin').on('hidden.bs.modal', function () {
            $('.errorMsg').html('');
            $('.dataForm')[0].reset();
        });

        $('#editWin').on('hidden.bs.modal', function () {
            $('.errorMsg').html('');
            $('.dataForm')[1].reset();
        });

        $('.myDatetime').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd', //日期格式
            weekStart: 1, //一周从周一开始
            autoclose: true, //选择日期后关闭
            startView: 'month', //默认打开月
            minView: 'month',
            todayBtn: true,
            forceParse: false
        });
    });

    //初始化表格
    function initTable() {
        //调用组件配置异步表格
        $('#tab').bootstrapTable({
            //http请求方式
            method: 'get',
            url: 'activity/page',
            //工具栏
            toolbar: '#toolbar',
            //点击选中
            clickToSelect: true,
            //单选
            singleSelect: false,
            //处理响应数据格式
            responseHandler: function (res) {
                if (res.code == 0) {
                    return {
                        rows: res.data.list,
                        total: res.data.total
                    };
                }
            },
            //开启分页
            pagination: true,
            //设置服务器端分页
            sidePagination: 'server',
            //设置每页条数
            pageSize: 5,
            //设置每页条数列表
            pageList: [5, 10, 15, 20],
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            //设置bootstrapTable向后台提交分页数据
            queryParamsType: '',
            queryParams: function (params) {
                params.name = $('#name').val();
                params.owner = $('#owner').val();
                params.startDate = $('#startDate').val();
                params.endDate = $('#endDate').val();
                return params;
            },
            showRefresh: true,
            showToggle: true,
            showFullscreen: true,
            //表格中列描述
            columns: [
                {
                    checkbox: true
                }, {
                    field: 'id',
                    visible: false
                }, {
                    title: '名称',
                    field: 'name',
                    halign: 'center',
                    //列数据格式化
                    formatter: function (value, row) {
                        //格式化之后的列数据
                        return '<a href="activity/detail/' + row.id + '">' + value + '</a>';
                    }
                }, {
                    title: '所有者',
                    field: 'userName',
                    halign: 'center'
                }, {
                    title: '开始日期',
                    field: 'startDate',
                    halign: 'center'
                }, {
                    title: '结束日期',
                    field: 'endDate',
                    halign: 'center'
                }, {
                    title: '创建者',
                    field: 'createBy',
                    halign: 'center'
                }, {
                    title: '创建时间',
                    field: 'createTime',
                    halign: 'center'
                }, {
                    title: '修改者',
                    field: 'editBy',
                    halign: 'center'
                }, {
                    title: '修改时间',
                    field: 'editTime',
                    halign: 'center'
                }, {
                    title: '操作',
                    halign: 'center',
                    align: 'center',
                    formatter: function (value, row) {
                        return '<button type="button" title="编辑" class="btn btn-warning btn-xs" onclick="get(\'' + row.id +
                            '\')"><span class="glyphicon glyphicon-edit"></span></button>&emsp;' +
                            '<button type="button" title="删除" class="btn btn-danger btn-xs" onclick="remove(\'' + row.id +
                            '\')"><span class="glyphicon glyphicon-trash"></span></button>';
                    }
                }
            ]
        });
    }
</script>
</body>
</html>